﻿@{
    ViewBag.Title = "工作调度系统";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/default/easyui.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.easyui.min.js")" type="text/javascript"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/style/style.css" />
</head>


<script type="text/javascript" language="javascript">

    $(function () {
        $("#dataGridDiv").datagrid({
            url: "/Home/showWorkJob",
            loadMsg: "数据加载中，请稍后...",
            //fitCloumns: true,
            width: 1160,
            height: 500,
            nowrap: true,
            rownumbers: false,
            singleSelect: true,
            showFooter: true,
            queryParams: {},
            columns: [[
            { field: 'jobName', title: '工作名', width: 200, align: "center" },
            { field: 'beginDateTime', title: '工作开始时间', width: 200, align: "center" },
            { field: 'endDateTime', title: '工作结束时间', width: 200, align: "center" },
            { field: 'triggertime', title: '工作触发时间', width: 150, align: "center" },
            { field: 'cronExpression', title: 'Cron表达式', width: 150, align: "center" },
            { field: 'descriptionInfo', title: '对工作的简单描述', width: 250, align: "center" }
        ]],
            onDblClickRow: function (index, data) {

            },
            onLoadSuccess: function (data) { },
            onRowContextMenu: function (e, rowIndex, rowData) {
                onRowContextMenuFn(e, rowIndex)
            }
        });

        $('#tab').tabs({
            fit: true,
            plain: true,
            onSelect: function (title) {
                Tabselect(title);
            }
        });
        $('#tt').tree({
            url: "/Home/showJobTree",
            onClick: function (node) {
                $(this).tree('toggle', node.target);
                //alert('you dbclick '+node.text);
                if ($("#tt").tree("getChildren", node.target) == "") {
                    if ($('#tab').tabs('exists', node.text)) {//如果tab已经存在,则选中并刷新该tab          
                        $('#tab').tabs('select', node.text);
                        //        refreshTab({tabTitle:title,url:href});  
                    } else {
                        $("<div/>").appendTo("#windowsDiv").attr("id", "Div_" + node.text);
                        $("#Div_" + node.text).html
                    ('<iframe scrolling="yes" frameborder="0"  src="/Home/JobSet?jobID=' + node.id
                    + '&jobClass=' + node.attributes.jobClass + '" style="width:100%;height:425px;" id="iframe_"'
                    + node.text + '"></iframe>')
                        $("#Div_" + node.text).window({
                            title: node.text,
                            width: 600,
                            modal: false,
                            height: 470,
                            onClose: function () {
                                $("#Div_" + node.text).empty();
                                $("#Div_" + node.text).remove();
                                $('#tab').tabs('close', node.text);
                            }
                        });
                        $('#tab').tabs('add', {
                            content: '',
                            title: node.text,
                            closable: false
                        });
                    }
                }
            }
        });
    });
    function onRowContextMenuFn(e, rowIndex) {
        e.preventDefault();
        $("#dataGridDiv").datagrid('unselectAll');
        $("#dataGridDiv").datagrid('selectRow', rowIndex);
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });

    }
    function endWork() {
        var selectRow = $("#dataGridDiv").datagrid('getSelected');
        $.ajax({
            type: 'POST',
            url: "/Home/EndScheduler",
            data: { jobName: selectRow.jobName },
            dataType: "json",
            success: function (msg) {
                if (msg == 1) {
                    ReloadDatagrid();
                    alert("停止了该工作！");
                }
                else {
                    alert(msg);
                }
            }
        });
    }
    function ReloadDatagrid() {
        $('#dataGridDiv').datagrid('load');
    } 
    function Tabselect(title) {
        $("#Div_" + title).window('restore');
        $("#Div_" + title).window('open');
    }
</script>
<body class="easyui-layout">@*<div class="post">
 <div class="news">工作调度系统</div>
</div>
    <div class="main">
	<div class="easyui-layout" style="width:1003px;height:520px;">*@
    <div region="north" border="false" class="post"><center><h2>工作调度系统</h2></center></div>
		<div region="west" split="true" title='<div class="nav_tit">工作栏</div>' style="width:150px;">
           <div id="tt"></div>
		</div>
		<div region="center"  style="background:#fafafa;overflow:hidden">             <div id="windowsDiv"></div>
             <div id="dataGridDiv"></div>
         </div>
         <div region="south"  style="height:30px;">
             <div id="tab"  style="height:20px;" ></div>
         </div>
         <div id="mm" class="easyui-menu" style="width:120px;">
		    <div onclick="endWork()">停止该工作</div>
	    </div>
    </body>
    </html>
